<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
</head>
<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<xblock>
    <button shiro:hasPermission="del" class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
    <button class="layui-btn" onclick="x_admin_show('添加用户','/staff/add')"><i class="layui-icon"></i>添加</button>
</xblock>
<table class="layui-table">
    <thead>
    <tr>
        <th>
            <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
        </th>
        <th hidden="hidden">ID</th>
        <th >用户名</th>
        <th >姓名</th>
        <th>电话</th>
        <th>地址</th>
        <th>操作</th>
    </thead>
    <tbody>
    <tr th:each="x:${staffList}">
        <td>
            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
        </td>
        <td hidden="hidden" th:text="${x.staffId}"></td>
        <td th:text="${x.staffUsername}"></td>
        <td th:text="${x.staffName}"></td>
        <td th:text="${x.staffTel}"></td>
        <td th:text="${x.staffAddr}"></td>
        <td><a title="修改"  onclick="update(this)" href="javascript:;">
            <i class="layui-icon">&#xe642;</i>修改
        </a>
            <a shiro:hasPermission="del" title="删除" onclick="member_del(this)" href="javascript:;">
                <i class="layui-icon">&#xe640;</i>删除
            </a></td>
    </tr>
    </tbody>
</table>
<!--<div class="page">-->
<!--    <div>-->
<!--        <a class="prev" th:href="@{/permission/pageList(page=${prePage})}">&lt;&lt;</a>-->
<!--        <a class="num" href="/permission/pageList">首页</a>-->
<!--        <span class="current" th:text="${curPage}"></span>-->
<!--        <a class="num" th:href="@{/permission/pageList(page=${totalPages})}">尾页</a>-->
<!--        <a class="next" th:href="@{/permission/pageList(page=${nextPage})}">&gt;&gt;</a>-->
<!--    </div>-->
<!--</div>-->
</div>
</body>
</html>
<script>
    //打开修改页面
    /*用户-编辑*/
    function update(obj) {
        var staffId=$(obj).parents("tr").find("td").eq(1).text();
        var url ='/staff/edit?staffId='+staffId
        x_admin_show('信息修改',url)
    }

    //批量删除
    function delAll () {
        //获取复选框选中的用户的uId
        var data = tableCheck.getData().toString();

        layer.confirm('确认要删除吗？'+data,function(index){
            $.ajax({
                url:"/staff/delAll",
                async: false,
                type:"POST",
                dataType: "json",
                data:{"permissionIds":data},
                success: function(data){
                    if(data==true){
                        layer.msg('删除成功', {icon: 1});
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }else{
                        layer.msg('删除失败!',{icon: 1,time:1000});
                    }

                }
            })

        });
    }

    /*用户-删除*/
    function member_del(obj){
        //获取要删除用户的编号staffId
        var staffId=$(obj).parents("tr").find("td").eq(1).text();
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                url:"/staff/del",
                async: false,
                type:"POST",
                dataType: "json",
                data:{"StaffId":staffId},
                success: function(data){
                    if(data==true){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else{
                        layer.msg('删除失败!',{icon: 1,time:1000});
                    }

                }
            })

        });
    }

</script>
